import os


def get_target_file_name(csv_file, target_id):
    (path, file_) = os.path.split(csv_file)
    return path + '/' + str(target_id) + '.csv'

def clear_console(fnc):
    def wrapper(*args,**kw):
        os.system(['clear','cls'][os.name == 'nt'])
        return fnc(*args,**kw)
    return wrapper

    

def split_number_unit(number_with_unit): 
    """
    Splits given number with unit in string format into number and unit items.
    input : number_with_unit : str : "32" | "32GB" | "32 GB"
    output: (number,unit) : (int,str) : (32,) | (32,GB) | (32, GB)
    exception: raises ValueError when number_with_unit is not start with digit. : "GB" | "GB 123" | " 12"
    """
    if is_number(number_with_unit):
        return (int(number_with_unit), None)
    
    has_digit = False   
    for i,c in enumerate(number_with_unit):
        if not c.isdigit():
            break
        has_digit = True
        
    if not has_digit:
        raise ValueError(number_with_unit + ' is only unit!')
        
    return (int(number_with_unit[:i]),number_with_unit[i:].strip())

def is_number(s):
    try:
        float(s)
        return True
    except ValueError:
        return False

if __name__ == '__main__':
    """
    Tests for split_number_unit
    """
    (number, unit) = split_number_unit("32GB")
    assert (number == 32 and unit == 'GB')
    
    (number, unit) = split_number_unit("12 GB")
    assert (number == 12 and unit == 'GB')
    
    (number, unit) = split_number_unit("02 GB")
    assert (number == 2 and unit == 'GB')
    
    (number, unit) = split_number_unit("5")
    assert (number == 5 and unit == None)
    
    (number, unit) = split_number_unit("33")
    assert (number == 33 and unit == None)
    
    try:
        split_number_unit("GB")
        assert False
    except ValueError:
        pass
    